﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Craps
{
    class Craps
    {
        //create random-number generator for use in method RollDice
        private Random randomNumbers = new Random();

        //enumeration with constants that represent the game status   constant--常量
        private enum Status { CONTINUE, WON, LOSE }

        //enumeration with constants that represent common rolls of the dice
        private enum DiceNames { 
            SNAKE_EYES = 2,
            TREY = 3,
            SEVEN = 7,
            YO_LEVEN = 11,
            BOX_CARS = 12
        }//end enum DiceName

        public void Play()
        {
            //gameStatus can contain CONTINUE WON LOST
            Status gameStatus = Status.CONTINUE;
            int myPoint = 0; //point if no win or lose on first roll

            int sumOfDice = RollDice(); //first roll of dice 

            //determine game status and point on first roll
            switch ((DiceNames)sumOfDice)
            {
                case DiceNames.SEVEN:
                case DiceNames.YO_LEVEN:
                    gameStatus = Status.WON;
                    break;
                case DiceNames.BOX_CARS:
                case DiceNames.SNAKE_EYES:
                case DiceNames.TREY:
                    gameStatus = Status.LOSE;
                    break;
                default:
                    gameStatus = Status.CONTINUE;
                    myPoint = sumOfDice;
                    Console.WriteLine("My point: {0}", myPoint);
                    break;
            }//end switch

            //while game is not complete
            while (Status.CONTINUE == gameStatus) //game not won or lost
            {
                sumOfDice = RollDice();  //roll dice again

                if (7 == sumOfDice)     //lose by rolling 7 before point
                {
                    gameStatus = Status.LOSE;
                }
                else if (myPoint == sumOfDice)    //win by making point
                {
                    gameStatus = Status.WON;
                }
            }//end while 

            if (Status.WON == gameStatus)
            {
                Console.WriteLine("Player WON!!!");
            }
            if (Status.LOSE == gameStatus)
            {
                Console.WriteLine("Player LOSE!!!");
            }
        }//end method Play
        private int RollDice()   //roll--滚动   dice--骰子
        {
            //pick random die value        
            int die1 = randomNumbers.Next(1, 7); //first die roll     die--骰(tou第二声)子
            int die2 = randomNumbers.Next(1, 7);//second die roll   

            int sum = die1 + die2; //sum of die values

            //display result of this roll
            Console.WriteLine("Player rolled {0} + {1} = {2}",die1,die2,sum);

            return sum;//return sum of dice 
        }//end method RollDice
    }//end class Craps
}
